package mail;

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Properties;
import jakarta.mail.Session;
import jakarta.mail.internet.MimeMessage;

public class SendMail {

	public static void sendMail(String to,String content) {
		String popServer="smtp.126.com";
		String user="yjy18830656149@126.com";
		String auth_code="UXBQVUTWWBGCFJNR";
		
		Properties pro=new Properties();
		pro.put("mail.transport.protocol", "smtp");
		pro.put("mail.smtp.host", "server");
		pro.put("mail.smtp.auth", true);
		//1.创建Session
		Session session=Session.getInstance(pro, new jakarta.mail.Authenticator() {
//			@Override
			protected PasswordAuthentication getPasswordAuthenticator{
				return new PasswordAuthentication(from, auth_code);
			}
		});
		//2.创建邮件
		Message message=new MimeMessage(session);
		message.setFrom(new InternetAddress(from));
		message.addRecipient(RecipientType.TO,new InternetAddress(to));
		message.setRecipient(RecipientType.TO,new InternetAddress(to));
		message.setSubject("hello");
		message.setText(content);
		message.setSentDate(new Date());
		Transport.send(message);
		System.out.println("发送成功");
	}
}
